public class Test {
    final static String salutation = "Hello! ";
    public static void main(String[] args) {

        Test tester = new Test();

        //类型声明
        MathOperation addition = (int a, int b) -> a + b;

        //不用类型声明
        MathOperation subtraction = (a,b) -> a-b;

        //大括号中的返回语句
        MathOperation multiplication = (int a, int b)->{return a * b;};

        int c = addition.operation(2,5);
        System.out.println(c);

        //没有大括号即返回语句
        MathOperation division = (int a,int b)->a/b;
        System.out.println("10 + 5 =" + tester.operate(10,5,addition));
        System.out.println("10 + 5 =" + tester.operate(10,5,(int a,int b)->a+b));
        System.out.println("10 - 5 =" + tester.operate(10,5,subtraction));
        System.out.println("10 * 5 =" + tester.operate(10,5,multiplication));
        System.out.println("10 / 5 =" + tester.operate(10,5,division));

        //不用括号
        GreetingService greetingService1 = message ->
                System.out.println("hello " + message);

        //用括号
        GreetingService greetingService2 = message ->
        {
            System.out.println("Hello " + message);
        };

        GreetingService greetingService3 = (message) ->
                System.out.println(salutation+message);

        greetingService1.sayMessage("Runnoob");
        greetingService2.sayMessage("Google");
        greetingService3.sayMessage("Sun");

        int num = 1;
        MathOperation mathOperation = (a,b)->num+a+b;
        System.out.println(tester.operate(1,2,mathOperation));
    }

    interface MathOperation{
        int operation(int a,int b);
    }
    interface GreetingService{
       void sayMessage(String message);
    }
    private int operate(int a, int b, MathOperation mathOperation){
        return mathOperation.operation(a,b);
    }
}
